<template>
  <div>
    <el-row type="flex" justify="end">

      <el-select v-model="currentYear" size="small" style="width: 120px">
        <el-option v-for="item in yearsList" :key="item" :label="item" :value="item">{{ item }}</el-option>
      </el-select>
      <el-select v-model="currentMonth" size="small" style="width: 120px">
        <el-option v-for="item in 12" :key="item" :label="item" :value="item">{{ item }}</el-option>

      </el-select>

    </el-row>

    <el-row>
      <el-calendar v-model="currentDate">
        <template v-slot:dateCell="{ date, data }" class="content">
          <div class="date-content">
            <span class="text"> {{ data.day | getDay }}</span>
            <span v-if="isWeek(date)" class="rest">休</span>
          </div>
        </template>
      </el-calendar>
    </el-row>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  name: 'WorkCalendar',
  components: {},
  filters: {
    getDay(data) {
      return moment(data).format('D')
    }
  },
  props: {
    startData: {
      type: Date,
      default: () => new Date()
    }
  },
  data() {
    return {
      value: new Date(),
      currentMonth: null,
      currentYear: null,
      yearsList: []
    }
  },
  computed: {
    currentDate() {
      return `${this.currentYear}-${this.currentMonth}-1`
    }
  },
  created() {
    const currentYear = this.startData.getFullYear()
    this.currentYear = currentYear
    this.currentMonth = this.startData.getMonth() + 1
    // 方式1 通过for循环
    for (let i = -5; i <= 5; i++) {
      this.yearsList.push(currentYear + i)
    }
    // 目标生成数组[0,10]
    // [0,...10]
    // 方式2.通过Array.from-简化版
    // Array.from(Array(11)).forEach((t, i) => {
    //   this.yearList.push(currentYear + i - 5)
    // })
    // 方式3.通过Array.from-完整版
    // Array.from(Array(11), (t, i) => {
    //   this.yearList.push(currentYear + i - 5)
    // })
  },
  methods: {
    isWeek(data) {
      return data.getDay() === 6 || data.getDay() === 0
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-calendar__header{
  display: none !important;
}
::v-deep .el-calendar-table__row td,::v-deep .el-calendar-table tr td:first-child,  ::v-deep .el-calendar-table__row td.prev{
  border:none;
 }
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text{
  width: 20px;
  height: 20px;
  line-height: 20px;
 display: inline-block;

}
::v-deep .el-calendar-table td.is-selected .text{
   background: #409eff;
   color: #fff;
   border-radius: 50%;
 }
::v-deep .el-calendar__header {
   display: none
 }
</style>
